home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / RGASM.RAR / ASMCODE.EXE / CHAPT9 / FILESERV.ASM < prev    next >
Encoding:
Assembly Source File  |  1993-05-10  |  3.0 KB  |  108 lines

  1. ;
  2. ;       Program FileServ ( Chapter 9 )
  3. ;
  4.     page    55,132
  5.     NAME    FileServ
  6.     INCLUDE EXTENDA.INC
  7.  
  8.     CODESEG FileServ
  9.     DATASEG
  10.  
  11.     CLpublic <FileSize, FileAttr, CurDisk>
  12.  
  13.     CLstatic <long FileLen, long Fattr, long Fdate, long NDisk >
  14.  
  15. DTA     db      21 dup (?)
  16. Attrib  db      ?       ;======== 01 -  Read Only
  17.                 ; 02 -  Hidden
  18.                 ; 04 -  System
  19.                 ; 08 -  Volume Id
  20.                 ; 10 -  Directory
  21.                 ; 20 -  Archive
  22. Time    dw      ?
  23. Date    dw      ?
  24. SizeF   dd      1951
  25. NameF   db      13 dup (' ')
  26.     db      90 dup (0)
  27.     db      0
  28. AttribF db      2
  29. SrcFile db      76 dup (0)
  30.  
  31.     WORKFUNCS
  32.  
  33. FindF   proc    near
  34. AccPrm: mov     al,es:[si+bx]           ; Take one byte from file name
  35.     cmp     al,' '                  ; Is it blank?
  36.     jne     NotBlank                ; If not - proceed the next byte
  37.     mov     al,0                    ; Else replace it with 0
  38. NotBlank:                               ;
  39.     mov     SrcFile[bx],al          ; Copy the byte into work area
  40.     inc     bx                      ; Increase the counter
  41.     loop    AccPrm                  ; Next byte
  42.                     ;
  43.     lea     dx,DTA                  ; Load addres of DTA into DS:DX
  44.     mov     ah,1Ah                  ; Function 1Ah -
  45.     int     21h                     ; DOS service call
  46.                     ;
  47.     lea     dx,SrcFile              ; Addres of ASCIIZ file name into DS:DX
  48.     mov     cx,3Fh                  ; Attribute 3Fh - any file
  49.     mov     ah,4Eh                  ; Function 4Eh - FindFirst
  50.     int     21h                     ; Dos service call
  51.     ret
  52. FindF   endp
  53.  
  54.     ENDWORK
  55.     
  56.     CLfunc  long FileSize <char fname>
  57.     CLcode
  58.  
  59.     mov     bx,0                    ;
  60.     mov     cx,80                   ; Maximal length of file name
  61.     les     si,fname                ; File name address into ES:SI
  62.  
  63.     call    FindF
  64.  
  65.     jnc     Success                 ;If CARRY flag isn't set - successful
  66.     mov     word ptr SizeF,-1       ;    else set return value to -1
  67.     mov     word ptr SizeF[2],-1    ;   to signal that file not found
  68.  
  69. Success:mov     ax,word ptr SizeF       ; Plase length of file into DX:AX
  70.     mov     dx,word ptr Sizef[2]    ;    to return it as FORTRAN function
  71.     mov     word ptr FILELEN[0],ax
  72.     mov     word ptr FILELEN[2],dx
  73.  
  74.     CLret   FILELEN
  75.  
  76.     CLfunc  long FileAttr <char fname>
  77.     CLcode
  78.  
  79.     mov     bx,0                    ;
  80.     mov     cx,80                   ; Maximal length of file name
  81.     les     si,fname                ; File name address into ES:SI
  82.  
  83.     mov     word ptr FATTR[0],0
  84.     mov     word ptr FATTR[2],0
  85.     Call    FindF
  86.  
  87.     jc      RetFlen                 ; If CARRY flag isn't set - successful
  88.     mov     ah,0
  89.     mov     al,byte ptr Attrib      ; Place length of file into DX:AX
  90.     mov     word ptr FATTR[0],ax
  91. RetFlen:CLret   FATTR   
  92.     
  93.     CLfunc  long CurDisk <>
  94.     CLcode
  95.     
  96.     push    ds
  97.     mov     ah,32h                  ; function 32h - get drive parameters
  98.     mov     dl,0                    ; 0 - current drive
  99.     int     21h
  100.     mov     al,ds:[bx]
  101.     pop     ds
  102.     mov     word ptr NDisk[2],0
  103.     mov     ah,0
  104.     mov     word ptr NDisk[0],ax
  105. RetNDsk:CLret   NDisk
  106.     
  107.         END
  108.